package com.hxg.common.controller;

import com.hxg.common.service.BlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/bl/verify")
public class BlVerfiyController {

    @Autowired
    private BlService blService;

    @RequestMapping("/repeat")
    @ResponseBody
    public Map<String, Object> repeat(
            @RequestParam("value") String value,
            @RequestParam("tableName") String tableName,
            @RequestParam("col") String col,
            @RequestParam("primaryKey") String primaryKey,
            @RequestParam("primaryKeyValue") String primaryKeyValue
    ) {
        Map<String, Object> jsonMap = new HashMap<>();

        try {
            boolean flag = blService.repeat(value, tableName, col, primaryKey, primaryKeyValue);
            jsonMap.put("flag", flag);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMap.put("flag", false);
            jsonMap.put("errorMsg", e.getMessage());
        }

        return jsonMap;
    }

    @RequestMapping("/repeatAppId")
    @ResponseBody
    public Map<String, Object> repeatAppId(
            @RequestParam("appId") String appId,
            @RequestParam("value") String value,
            @RequestParam("tableName") String tableName,
            @RequestParam("col") String col,
            @RequestParam("primaryKey") String primaryKey,
            @RequestParam("primaryKeyValue") String primaryKeyValue
    ) {
        Map<String, Object> jsonMap = new HashMap<>();

        try {
            boolean flag = blService.repeatAppId(appId, value, tableName, col, primaryKey, primaryKeyValue);
            jsonMap.put("flag", flag);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMap.put("flag", false);
            jsonMap.put("errorMsg", e.getMessage());
        }

        return jsonMap;
    }
}
